//
//  BabyGrowEntry.m
//  BabyHelper
//
//  Created by  thomas on 11-6-25.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BabyGrowEntry.h"
#import "Dao.h"

@implementation BabyGrowEntry

@synthesize index,name,weight,height,headCir,comments, timestamp,photoPath,thumPath,photo,photoID;


-(NSString*) getTimeWithOutYear {
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateFormat:DATE_TIME_FORMAT_NO_YEAR];
	NSString *strTime = [dateFormatter stringFromDate:self.timestamp];			
	[dateFormatter release];
	return strTime;
}

-(NSString*) getTimeStringWithYear {
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateFormat:DATE_TIME_FORMAT];
	NSString *strTime = [dateFormatter stringFromDate:self.timestamp];			
	[dateFormatter release];
	return strTime;
}


-(NSString*) getDateString {
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setDateFormat:DATE_FORMAT];
	NSString *strTime = [dateFormatter stringFromDate:self.timestamp];			
	[dateFormatter release];
	return strTime;
}

-(NSString*) getSummaryString {
	Dao *dao = [Dao getInstance];
	BabyProfile *babyProfile = [[[BabyProfile alloc]init] autorelease];
	[dao LoadBabyProfile:babyProfile];
	NSString *report = [NSString stringWithFormat:BABY_GROW_ENTRY_SUMMARY_STR,
						[dao GetAgeStringWithTwoDate:babyProfile.Birthday toDateTS:[self.timestamp timeIntervalSince1970]],
						self.height,
						self.weight,
						self.headCir];
	return report;
}

-(id) proxyForJson{
	return [NSDictionary dictionaryWithObjectsAndKeys:
			[NSNumber numberWithInt:index],@"index",
			[NSNumber numberWithFloat:height],@"height",
			[NSNumber numberWithFloat:height],@"weight",
			[NSNumber numberWithFloat:height],@"headCir",
			comments,@"comments",
			name,@"name",
			[self getTimeStringWithYear],@"timestamp",
			nil];
}
@end
